package cn.org.eshow.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 账单表
 */
@Entity
@Table(name = "bill")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Bill extends BaseObject implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;//账单ID

    @Column(name = "add_time")
    private Date addTime = new Date();// 添加时间

    @Column(length = 20)
    private String no;// 订单号

    @Column(length = 255)
    private String category;// 账单分类（用户，平台）

    @Column(length = 100)
    private String type;// 类型（消费支出，消费退款，平台订单收入,平台订单退款 , 平台线下退款）

    @Column
    private Double receive = 0.00;// 收到金额

    @Column
    private Double outlay = 0.00;// 支出金额

    @Column
    private Double balance = 0.00;// 账户余额

    @Column(length = 200)
    private String img;//图片地址

    @Column(name = "order_type", length = 20)
    private String orderType;//外部订单类型

    @Column(name = "order_no", length = 20)
    private String orderNo;//外部订单号

    @Column
    private Integer state = 0;// 状态（0未完成，1已成功）

    @Column(length = 400)
    private String remark;// 备注

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    private User user;// 用户

    public Bill() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getAddTime() {
        return addTime;
    }

    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Double getReceive() {
        return receive;
    }

    public void setReceive(Double receive) {
        this.receive = receive;
    }

    public Double getOutlay() {
        return outlay;
    }

    public void setOutlay(Double outlay) {
        this.outlay = outlay;
    }

    public Double getBalance() {
        return balance;
    }

    public void setBalance(Double balance) {
        this.balance = balance;
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }

    public String getOrderType() {
        return orderType;
    }

    public void setOrderType(String orderType) {
        this.orderType = orderType;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;

        Bill pojo = (Bill) o;
        if (id != null ? !id.equals(pojo.id) : pojo.id != null)
            return false;
        if (addTime != null ? !addTime.equals(pojo.addTime) : pojo.addTime != null)
            return false;
        if (no != null ? !no.equals(pojo.no) : pojo.no != null)
            return false;
        if (category != null ? !category.equals(pojo.category) : pojo.category != null)
            return false;
        if (type != null ? !type.equals(pojo.type) : pojo.type != null)
            return false;
        if (receive != null ? !receive.equals(pojo.receive) : pojo.receive != null)
            return false;
        if (outlay != null ? !outlay.equals(pojo.type) : pojo.outlay != null)
            return false;
        if (balance != null ? !balance.equals(pojo.balance) : pojo.balance != null)
            return false;
        if (img != null ? !img.equals(pojo.img) : pojo.img != null)
            return false;
        if (orderType != null ? !orderType.equals(pojo.orderType) : pojo.orderType != null)
            return false;
        if (orderNo != null ? !orderNo.equals(pojo.orderNo) : pojo.orderNo != null)
            return false;
        if (state != null ? !state.equals(pojo.state) : pojo.state != null)
            return false;
        if (remark != null ? !remark.equals(pojo.remark) : pojo.remark != null)
            return false;
        if (user != null ? !user.equals(pojo.user) : pojo.user != null)
            return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = result + (id != null ? id.hashCode() : 0);
        result = 31 * result + (addTime != null ? addTime.hashCode() : 0);
        result = 31 * result + (no != null ? no.hashCode() : 0);
        result = 31 * result + (category != null ? category.hashCode() : 0);
        result = 31 * result + (type != null ? type.hashCode() : 0);
        result = 31 * result + (receive != null ? receive.hashCode() : 0);
        result = 31 * result + (outlay != null ? outlay.hashCode() : 0);
        result = 31 * result + (balance != null ? balance.hashCode() : 0);
        result = 31 * result + (img != null ? img.hashCode() : 0);
        result = 31 * result + (orderType != null ? orderType.hashCode() : 0);
        result = 31 * result + (orderNo != null ? orderNo.hashCode() : 0);
        result = 31 * result + (state != null ? state.hashCode() : 0);
        result = 31 * result + (remark != null ? remark.hashCode() : 0);
        result = 31 * result + (user != null ? user.hashCode() : 0);
        return result;
    }

    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", this.id)
                .append("addTime", this.addTime)
                .append("no", this.no)
                .append("category", this.category)
                .append("type", this.type)
                .append("receive", this.receive)
                .append("outlay", this.outlay)
                .append("balance", this.balance)
                .append("img", this.img)
                .append("orderType", this.orderType)
                .append("orderNo", this.orderNo)
                .append("state", this.state)
                .append("remark", this.remark)
                .append("user", this.user)
                .toString();
    }
}
